#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5,MA = 3e5;
string str[31];
int n,m,a[N + 5],aa[N + 5],c[N + 5],t,x[5],k,ans;
signed main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
        cin >> aa[i];
    for(int i = 1;i <= m;i++)
        cin >> c[i];
    for(k = 1;k <= 31;k++)
        if (pow(2,k) >= n)
            break;
    for(int i = 1;i <= k;i++)
        cin >> str[i];
    cin >> t;
    for(int i = 1;i <= t;i++){
        for(int i = 0;i <= 3;i++)
            cin >> x[i];
        cout << i << endl;
    }
    return 0;
}